<!-- 解决layer.open 不居中问题 -->
<!DOCTYPE html>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="utf-8">
    <title>添加质量体系</title>
    <!--引入抽取css文件-->
    <%@include file="../common/public-css.jsp" %>
    <style>
        .preview {
            height: 250px;
            width: 400px;
            margin-right: 10px;
            margin-bottom: 10px;
            float: left;
            text-align: center
        }

        .preview img {
            width: 100%;
            height: 210px;
            border: 1px solid #eee;
        }

    </style>
</head>
<body>
<div style="margin: 15px;">
    <blockquote class="layui-elem-quote"><i class="fa fa-refresh" aria-hidden="true"></i>&nbsp;表单带有 <span
            class="font-red">“*”</span> 号的为必填项.
    </blockquote>
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
        <legend>添加质量体系</legend>
    </fieldset>
    <form class="layui-form" action="" id="formData">

        <div class="layui-form-item">
            <label class="layui-form-label">选择类别<span class="font-red">*</span></label>
            <div class="layui-input-inline">
                <select id="categoryId" lay-filter="categoryFilter" lay-search>
                    <option value="">请选择一类</option>
                </select>
            </div>
            <div class="layui-input-inline">
                <select name="childCategoryId" id="childCategoryId" required lay-verify="required" lay-search>
                    <option value="">请选择二类</option>
                </select>
            </div>
        </div>


        <div class="layui-form-item">
            <label class="layui-form-label">名称<span class="font-red">*</span></label>
            <div class="layui-input-inline">
                <input type="text" class="layui-input" autocomplete="off" required lay-verify="required"  name="qualityName" id="qualityName" placeholder="输入名称">
            </div>
        </div>

        <div class="layui-form-item ">
            <label class="layui-form-label"><span>描述</span></label>
            <div class="layui-input-inline">
                <input type="text" name="qualityDescribe" autocomplete="off" id="qualityDescribe" placeholder="请输入描述" autocomplete="off"
                       class="layui-input" maxlength="250">
            </div>
        </div>

        <div class="layui-form-item ">
            <label class="layui-form-label"><span>备注</span></label>
            <div class="layui-input-inline">
                <input type="text" name="remark" id="remark" autocomplete="off" placeholder="请输入备注" autocomplete="off"
                       class="layui-input" maxlength="250">
            </div>
        </div>

        <div class="layui-form-item" id="otherAttachmentDiv">
            <label class="layui-form-label">模版附件<span class="font-red">*</span></label>
            <div class="layui-input-inline">
                <input type="text" disabled autocomplete="off" name="attachment" required lay-verify="required"  id="attachment" placeholder="未上传"
                       class="layui-input" maxlength="250">

            </div>
            <div class="layui-input-inline">
                <button type="button" class="layui-btn" id="uploadAttachment">
                    <i class="layui-icon">&#xe608;</i>上传模版
                </button>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>

</div>
<!--引入抽取公共js-->
<%@include file="../common/public-js.jsp" %>
<script src="<%=request.getContextPath()%>/resources/js/common/jQuery.md5.js"></script>
<script>
    var form = null;
    layui.use(['form', 'layedit', 'laydate', 'upload', 'layedit'], function () {
        form = layui.form,
                layer = layui.layer,
                layedit = layui.layedit
                , $ = layui.jquery,
                laydate = layui.laydate,
                upload = layui.upload;

        buildCategorySelect(0,"categoryId");
        form.render();
        form.on('select(categoryFilter)', function(data){
            // console.log(data.elem); //得到select原始DOM对象
            // console.log(data.value); //得到被选中的值
            buildCategoryChildSelect(0,"childCategoryId",data.value)
            form.render();
        });


        upload.render({
            elem: '#uploadAttachment' //绑定元素
            ,method : 'post'
            ,accept:"file"
            ,data : {path : 'iems/attachment'}
            ,url: Global.imageServer+'upload/files/' //上传接口
            ,done: function(res){
                //上传完毕回调
                console.log(res.body[0].sourcePath)
                $("#attachment").val(res.body[0].sourcePath);
            }
            ,error: function(){
                //请求异常回调
                layer.msg("上传失败");
            }
        });

        //监听提交
        form.on('submit(demo1)', function (data) {
            AM.ajaxRequestData("post", false, AM.ip + "/qualityItem/save", data.field, function (result) {
                if (result.flag == 0 && result.code == 200) {
                    //关闭iframe页面
                    var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                    parent.layer.close(index);
                    window.parent.closeNodeIframe();
                } else {
                    layer.msg(result.msg, {icon: 2, anim: 6});
                    return false;
                }
            });
            return false;
        });
    });




</script>
</body>
</html>
